<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Session;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{
   public function getIndex(Request $request)
   {

   		//前台首页
         /**
         *  将用于关注的兴趣挂体遍历到首页上
         */
   		$id = session('user_id');
   		//查询关注的tid
   		$str = DB::table('zheye_user_love')->where('uid',$id)->first();
   		$rep =  str_replace(',','',$str->tid);
   		$arr = DB::table('zheye_topic')->select('name')->get();
   		$row = [];
   		foreach ($arr as $k => $v) {

   			foreach ($v as $ks => $vs) {
   				 array_push($row,$vs);

   			}
   		}
   		$len = strlen($rep);
         
         for ($i=0; $i <$len ; $i++) { 
            // $ors .= '->'.'orwhere('."'tid_name'".",'".$row[$i]."')";
         }
   
         return view('/home/index',['row'=>$row,'len'=>$len]);
   }

   public function getPbl(Request $request)
   {

      $res = $request->all();
      
      $con = DB::table('zheye_article')
            ->where('status',1)
            ->orwhere('tid_name','php')
            ->orwhere('tid_name','js')
            ->orwhere('tid_name','bootstrap')
            ->orderBy('time','desc')
            ->skip($res['p'])->take($res['num'])
            ->get();

      for ($i=0; $i <$res['num'] ; $i++) { 
         $con[$i]->content_tag = iconv_substr(strip_tags($con[$i]->contents),0,230);
         
      }
      
      if(!empty($con)){

         echo json_encode($con);

      } else {

         echo false;
      }

     
   }

}
